package org.budo.cmbc.sdk.entity;

import org.budo.xml.XmlObject;

import lombok.extern.slf4j.Slf4j;

/**
 * @author lmw
 */
@Slf4j
public class OtherBankAgentPayResponse extends AbstractCmbcResponse {
    private static final long serialVersionUID = -5275879647449057639L;

    public OtherBankAgentPayResponse(String responseXml) {
        this.setResponseBody(responseXml);
    }

    public String getTrnId() {
        XmlObject xDataBody = this.xDataBody(this.getResponseBody());

        if (null == xDataBody) {
            log.error("#34 xDataBody=" + xDataBody + ", responseBody=" + this.getResponseBody());
            return null;
        }

        XmlObject otherBankAgentPay = xDataBody.getChildNodeByName("otherBankAgentPay");
        if (null == otherBankAgentPay) {
            log.error("#30 xDataBody=" + xDataBody + ", responseBody=" + this.getResponseBody());
            return null;
        }

        return otherBankAgentPay.getChildNodeTextContentByName("trnId");
    }

    public String getInsId() {
        XmlObject xDataBody = this.xDataBody(this.getResponseBody());

        if (null == xDataBody) {
            log.debug("#41 xDataBody={}, responseBody={}", xDataBody, this.getResponseBody());
            return null;
        }

        XmlObject otherBankAgentPay = xDataBody.getChildNodeByName("otherBankAgentPay");
        if (null == otherBankAgentPay) {
            log.error("#47 xDataBody=" + xDataBody + ", responseBody=" + this.getResponseBody());
            return null;
        }

        return otherBankAgentPay.getChildNodeTextContentByName("insId");
    }

    @Override
    public String toString() {
        return super.toString() + ", responseBody=" + this.getResponseBody();
    }
}

//<?xml version="1.0" encoding="UTF-8"?>
//<CMBC trnCode="otherBankAgentPay" security="none" lang="chs" header="100" version="100"> 
//  <responseHeader> 
//    <status> 
//      <code>0</code>  
//      <severity>info</severity>  
//      <message>ok</message> 
//    </status>  
//    <dtServer>2021-04-29 08:59:15</dtServer>  
//    <userKey>N</userKey>  
//    <dtDead/>  
//    <language>chs</language> 
//  </responseHeader>  
//  <xDataBody> 
//    <otherBankAgentPay> 
//      <trnId>TJ21429085914499</trnId>  
//      <insId>12345678</insId> 
//    </otherBankAgentPay> 
//  </xDataBody> 
//</CMBC>